﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sobiens.WPF.Controls.Classes
{
    public class PageInfos:List<PageInfo>
    {
        public PageInfo this[int pageIndex]
        {
            get
            {
                var query = from t in this
                            where t.Index == pageIndex
                            select t;

                return query.SingleOrDefault();
            }
        }

        public void Add(int pageIndex, string listItemCollectionPositionNext, int itemCount)
        {
            int startItemIndex = 1;
            int endItemIndex = itemCount;

            if (this[pageIndex-1] != null)
            {
                startItemIndex = this[pageIndex - 1].EndItemIndex + 1;
                endItemIndex = startItemIndex + itemCount - 1;
            }

            this.Add(new PageInfo()
            {
                Index = pageIndex,
                ListItemCollectionPositionNexts = listItemCollectionPositionNext,
                StartItemIndex = startItemIndex,
                EndItemIndex = endItemIndex
            }
            );
        }
    }
}
